<%!

  Copyright (c) Facebook, Inc. and its affiliates.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

%><%
// Computes lhs.{field} < rhs.{field}, assuming lhs.{field} != rhs.{field}.
%><%#field:cpp_ref?%><%
  // null comes first.
  // TODO(afuller): Move this to a shared helper function in the runtime.
  %>lhs.<%field:cpp_name%> == nullptr || (rhs.<%field:cpp_name%> != nullptr && *lhs.<%field:cpp_name%> < *rhs.<%field:cpp_name%>)<%
%><%/field:cpp_ref?%><%
%><%^field:cpp_ref?%><%
  %><%#type:raw_binary?%><%
    // Not all standard binary types define less operators, so we forward the check to StringTraits.
    // TODO(afuller): Move this to a shared helper function in the runtime.
    %><%#field:optional?%><%
      // Unset comes first.
      %>!lhs.<%field:cpp_name%>_ref().has_value() || (rhs.<%field:cpp_name%>_ref().has_value() && <%
    %><%/field:optional?%><%
    %>apache::thrift::StringTraits<<% > types/indirected_string_type%>>::isLess(<% > types/apply_indirection_pre%>lhs.<%field:cpp_name%><% > types/apply_indirection_post%>, <% > types/apply_indirection_pre%>rhs.<%field:cpp_name%><% > types/apply_indirection_post%>)<%
    %><%#field:optional?%>)<%/field:optional?%><%
  %><%/type:raw_binary?%><%
  %><%^type:raw_binary?%><%
    // Just use the field_ref impl.
    %>lhs.<%field:cpp_name%>_ref() < rhs.<%field:cpp_name%>_ref()<%
  %><%/type:raw_binary?%><%
%><%/field:cpp_ref?%>
